//
//  WebViewController.m
//  DaJiHui
//
//  Created by Mac on 2017/10/18.
//  Copyright © 2017年 Hao. All rights reserved.
//

#import "WebViewController.h"
#import <JavaScriptCore/JavaScriptCore.h>
#import "JavaScriptCoreBridge.h"
@interface WebViewController ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    self.webView.scrollView.bounces = false;
    self.webView.delegate = self;
    NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.chaojihui123.com/phone.php?s=/Index/index"]];
    [self.webView loadRequest:req];
    [self.view addSubview:self.webView];
}


//网页路由跳转
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return true;
}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //js 调用原生
    JSContext *jsContext = [webView  valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    jsContext[@"fenxiang"] = ^(){
        
    };
    
    //js方法名＋参数
    NSString* jsCode = [NSString stringWithFormat:@"fenxiang('%@')",@"aaa"];
    //调用html页面的js方法
    NSString *str = [webView stringByEvaluatingJavaScriptFromString:jsCode];
    
    
//    JavaScriptCoreBridge *js = [[JavaScriptCoreBridge alloc] init];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
